package com.example.litemall.admin.api.controller;

import com.example.litemall.admin.api.commons.RequiresPermissionsDesc;
import com.example.litemall.admin.api.commons.ResponseUtil;
import com.example.litemall.admin.api.domain.LitemallBrand;
import com.example.litemall.admin.api.service.LitemallBrandService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
*商城后台品牌管理
*
*@Author kuaiyu
*@Date 2020-07-21 14:20:34
*@see com.example.litemall.admin.api.controller
*/
@RestController
@RequestMapping("/admin/brand")
public class AdminBrandController {
    @Autowired
    private LitemallBrandService litemallBrandService;

    /**
     * 条件+分页查询
     * @param brand
     * @param page
     * @param limit
     * @return
     */
    @GetMapping("/list")
    @RequiresPermissions("admin:brand:list")
    @RequiresPermissionsDesc(menu = {"商场管理", "品牌管理"}, button = "查询")
    public Object getBrandList(LitemallBrand brand,
                              @RequestParam(defaultValue = "1") Integer page,
                              @RequestParam(defaultValue = "5") Integer limit){
        List<LitemallBrand> brands = litemallBrandService.getBrandList(brand,page, limit);
        return ResponseUtil.okList(brands);
    }

    @PostMapping("/create")
    public Object addBrand(@RequestBody LitemallBrand brand){
        litemallBrandService.addBrand(brand);
        return ResponseUtil.ok(brand);
    }
    @PostMapping("/update")
    public Object updateBrand(@RequestBody LitemallBrand brand){
        litemallBrandService.updateBrand(brand);
        return ResponseUtil.ok(brand);
    }


}
